<?php

class Users extends Admin_Controller
{
	
	public function __construct()
	{
		parent::__construct();
	}
	
	public function index()
	{
		$data['users'] = new User;
		if(@$_GET['fullname'])$data['users']->like('fullname',$_GET['fullname']);
		if(@$_GET['email'])$data['users']->like('email',$_GET['email']);
		if(@$_GET['level_id'])$data['users']->where('level_id',$_GET['level_id']);
		if(@$_GET['agency_id'])$data['users']->where('agency_id',$_GET['agency_id']);
		$data['users']->where('level_id >= '.user()->level_id)->get_page(50);
		$this->template->build('admin/users/index',$data);
	}
	
	public function form($id = NULL)
	{	
		$data['user'] = new User($id);
		$this->template->build('admin/users/form',$data);
	}
	
	public function save($id = NULL)
	{
		if($_POST)
		{
			$user = new User($id);
			$user->from_array($_POST);
			$user->save();
			set_notify('success', lang('save_data_complete'));	
		}
		redirect('users/admin/users');
	}
	
	public function delete($id)
	{
		if($id)
		{
			$user = new User($id);
			$user->delete();	
			set_notify('success', lang('delete_data_complete'));	
		}
		redirect('users/admin/users');
	}
	
	public function log()
	{
		$data['logs'] = new Log();
		$data['logs']->order_by('id','desc')->get_page();
		$this->template->build('admin/log/index',$data);
	}
	
}

?>